package cn.edu.scau.cmi.luotiansheng.composite.test;

import java.util.ArrayList;
import java.util.List;

public class Compsite extends Conponent{

	
	private List<Conponent> list=new ArrayList<Conponent>();
	
	
	
	public Compsite(String name,Conponent parent ) {
	
		this.name=name;
		this.parent=parent;
		if(parent==null) {
			this.deep=0;
		}else {
			this.deep=this.parent.deep+1;
		}
	}
	
	
	public void setDeep(Integer deep) {
		this.deep=deep;
	}
	
	public Integer getDeep() {
		return this.deep;
	}
	
	public void setName(String name) {
		this.name=name;
		
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setParent(Conponent parent) {
		this.parent=parent;
		
	}
	
	public Conponent getParent() {
		return this.parent;
	}
	
	
	public void add(Conponent child) {
		this.list.add(child);
	}
	
	public void delete(int index) {
		this.list.remove(index);
	}
	
	public List<Conponent> getList() {
		return this.list;
	}



	public void setList(List<Conponent> list) {
		this.list = list;
	}
	

	@Override
	public void show() {
		// TODO Auto-generated method stub
		
		
		for(int i=0;i<this.deep;i++) {
			System.out.print("\t");
		}
		if(this.getParent()!=null) {
			System.out.println(this.getParent().name+":  Compsite  "+this.name+" "+this.deep);
		}else {
			System.out.println("Root:  "+this.name+" "+this.deep);
		}
		
	}
	
	
	public void showList() {
		
		for(int i=0;i<this.list.size();i++) {
			Conponent conponent=this.list.get(i);
			conponent.show();
			
		}
		
	}
	
}
